package geeksforgeeks.trees;

import geeksforgeeks.trees.TreeTraversals.Node;

public class IsBST {
	public static void main(String[] args) {

		Node root = new Node(20);
		root.left = new Node(5);
		root.right = new Node(30);
		
		root.left.left = new Node(3);
		root.left.right = new Node(7);

		boolean ret = isBST(Integer.MIN_VALUE, root, Integer.MAX_VALUE);
		System.out.println(ret);

	}

	private static boolean isBST(int currMin, Node root, int currMax) {
		
		if(root == null)
			return true;

		if ( root.data > currMin && root.data < currMax) {
			return isBST(currMin, root.left, root.data)
					&& isBST(root.data, root.right, currMax);
		} else
			return false;

	}
}
